{% extends "../layouts/admin.html" %}
{% block content %}
<header class="header navbar bg-white shadow">
  <div class="btn-group tool-button">
    <a class="btn btn-primary navbar-btn" href="/system/rule/index" data-pjax id="goback"><i class="ti-angle-left"></i> 返回</a>
  </div>
  <div class="pull-right">
    <div class="btn-group tool-button">
      <button class="btn btn-primary navbar-btn" onclick="complete()"> 保存</button>
    </div>
  </div>
</header>
<div class="modal-body no-p">
  <div class="panel">
    <div class="panel-heading no-b">
    </div>
    <div class="panel-body" style="padding-top: 50px;">
      
      <div class="cf nestable-lists">
        <div class="dd" id="nestable3">
          <ol class="dd-list">
          	{% for firstMenu in firstMenus %}
            
            <li class="dd-item dd3-item" data-id="{{ firstMenu.id }}">
              <div class="dd-handle dd3-handle">Drag</div>
              <div class="dd3-content">{{ firstMenu.name }}</div>
              {% if secondMenus[firstMenu.id] %}
              <ol class="dd-list">
               
                	{% for secondMenu in secondMenus[firstMenu.id] %}
                	
                <li class="dd-item dd3-item" data-id="{{ secondMenu.id }}">
                  <div class="dd-handle dd3-handle">Drag</div>
                  <div class="dd3-content">{{ secondMenu.name }}</div>
                  {% if secondMenus[secondMenu.id] %}
                  
                  <ol class="dd-list">
                  	{% for thirdMenu in secondMenus[secondMenu.id] %}
                    
                    <li class="dd-item dd3-item" data-id="{{ thirdMenu.id }}">
                      <div class="dd-handle dd3-handle">Drag</div>
                      <div class="dd3-content">{{ thirdMenu.name }}</div>
                    </li>
                    {% endfor %}
                  </ol>
                  {% endif %}
                </li>
                {% endfor %}
              </ol>
               {% endif %}
            </li>
            {% endfor %}

          </ol>
        </div>
      </div>

    </div>
  </div>
</div>
<script type="text/javascript">
  function complete(){
    var ids = JSON.stringify($("#nestable3").nestable('serialize'));
    $.post("/system/rule/sort", {ids: ids}, function (data) {
      if (data.errno == 0) {
        Toast.success(data.data);
        setTimeout(function () {
          $("#goback").trigger("click");
        }, 1000);
      } else {
        Toast.error(data.errmsg);
      }
    }, "json");
  }
  $(function () {
    $("#nestable3").nestable();
  });

</script>
{% endblock %}